﻿// Notifies the suscribed views when a key up event occurs
define([
    'Wjs/ui/elements/notifiers/Notifier'
],
function () {
    'use strict';

    var Notifier = Wjs.getType('Notifier');

    return Wjs.defineOnce({

        type: 'keyupNotifier',

        'static': true,

        base: Notifier,

        // For static types this is fired when the instance is created
        onTypeDefined: function (keyupNotifier) {

            window.onkeyup = function (evt) {
                keyupNotifier.keyUpHandler(evt);
            };

        },

        // Notifies the subscribers about the key up event
        keyUpHandler: function (evt) {

            this.views.forEach(function (view) {

                if (view.keyUpHandler) {
                    view.keyUpHandler(evt);
                }
            });
        }
    });

});